package web.listeners;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.event.ValueChangeEvent;

import web.handle.CurrentUserBean;
import web.layout.OneDayForecastCheckbox;
import ejb.manager.UserManager;


@ManagedBean
public class OneDayForecastCheckboxListener {

	@EJB
	private UserManager userManager; 
	
	@ManagedProperty(value="#{oneDayForecastCheckbox}")
	private OneDayForecastCheckbox oneDayForecastCheckbox;
		
	@ManagedProperty(value="#{currentUserBean}")
	private CurrentUserBean currentUserBean;
		
	public OneDayForecastCheckboxListener(){}
	
	public OneDayForecastCheckbox getOneDayForecastCheckbox() {
		return oneDayForecastCheckbox;
	}

	public void setOneDayForecastCheckbox(
			OneDayForecastCheckbox oneDayForecastCheckbox) {
		this.oneDayForecastCheckbox = oneDayForecastCheckbox;
	}

	public CurrentUserBean getCurrentUserBean() {
		return currentUserBean;
	}

	public void setCurrentUserBean(CurrentUserBean currentUserBean) {
		this.currentUserBean = currentUserBean;
	}

	public void oneDayForecastCheckboxChanged(ValueChangeEvent e){
		if(oneDayForecastCheckbox.getOneDayForecastCheckbox().isSelected()){
			userManager.setForecast(currentUserBean.getUsername(), true);
		}else{
			userManager.setForecast(currentUserBean.getUsername(), false);
		}
	}
	

}
